<template>
  <div>
    <div v-if="row.actions.length>2">
      <a @click="handleClickMore(row.actions[0].name, row)">{{ row.actions ? row.actions[0].label : '' }}</a>
      <Divider type="vertical" />
      <Dropdown @on-click="(name) => handleClickMore(name, row)"
                transfer>
        <a>更多
          <Icon type="ios-arrow-down" /></a>
        <DropdownMenu slot="list">
          <DropdownItem v-for="(item, i) in row.actions.slice(1)"
                        :key="i"
                        :name="item.name">{{ item.label }}</DropdownItem>
        </DropdownMenu>
      </Dropdown>
    </div>
    <div v-else>
      <a v-if="row.actions"
         @click="handleClickMore(row.actions[0].name, row)">{{ row.actions[0].label }}</a>
      <Divider v-if="row.actions && row.actions.length>1"
               type="vertical" />
      <a v-if="row.actions && row.actions.length>1"
         @click="handleClickMore(row.actions[1].name, row)">{{ row.actions[1].label }}</a>
    </div>
    <!-- 加入黑名单 -->
    <Modal v-model="isPullBlack"
           title="加入黑名单"
           @on-ok="pullBlack(row)">
      <Form ref="thaw"
            :model="pullBlackInfo"
            :label-width="100">
        <Input v-model="inputReason"
               maxlength="100"
               show-word-limit
               type="textarea"
               placeholder="拉黑备注"
               style="width: 100%;height:100px;" />
      </Form>
    </Modal>
    <!-- end -->
  </div>

</template>
<script>
    import { ApiRequest } from '@api/basePage';
    import dynamictableactions from '@/mixins/dynamictableactions'; // 混入通用代码
    export default {
        mixins: [
            dynamictableactions
        ],
        data () {
            return {
                isPullBlack: false,
                pullBlackInfo: {},
                inputReason: ''
            }
        },
        methods: {
            // table 操作列点击事件
            handleClickMore (name, row) {
                let obj = {}; // 动作的对象信息
                row.actions.forEach(item => {
                    if (name === item.name) {
                        obj = item;
                        return false;
                    }
                })
                this.setTableRowData(row)
                if (obj.handleType === 'link') { // 操作类型为链接时，拼接参数跳转
                    let jumpPath = this.jumpPath + obj.name;
                    this.$router.push({ path: jumpPath, query: { 'uuid': row.uuid } })
                } else if (obj.handleType === 'alert') { // 操作类型为弹窗时 打开弹窗
                    if (obj.name === 'lahei') {
                        this.isPullBlack = true
                    }
                }
            },
            // 拉黑操作
            pullBlack (row) {
                let data = {
                    uuid: row.uuid,
                    inputReason: this.inputReason
                }
                // 开始请求拉黑接口
                ApiRequest(this.requestApi.pullBlackOfMerchant.url, this.requestApi.pullBlackOfMerchant.type, data).then(res => {
                    this.$Message.success('加入黑名单成功');
                    this.actionsChange();
                })
            }
        }
    }
</script>
